﻿using System;
using System.Net;
using System.Net.Mail;
using Messaging.Configuration;

namespace Messaging.Senders
{
    internal class MessageSender : IMessageSender
    {
        public void Send(MailMessage message)
        {
            try
            {
                var client = new SmtpClient(SMTPConfig.SmtpServer, SMTPConfig.SmtpPort)
                                 {
                                     EnableSsl = SMTPConfig.SmtpEnableSSL,
                                     UseDefaultCredentials = SMTPConfig.SmtpUseDefaultCredentials
                                 };

                if (!SMTPConfig.SmtpUseDefaultCredentials)
                    client.Credentials = new NetworkCredential(SMTPConfig.SmtpUserName, SMTPConfig.SmtpPassword);
                
                client.Send(message);
            }
            catch(Exception ex)
            {
                //TODO: Write to log
            }
        }
    }
}
